1
|
|
|
/* function to parse the input and exchanges , with . |
2
|
|
|
*/ |
3
|
|
|
function parse_input(string) { |
4
|
|
|
return parseFloat(string.replace(',' , '.')); |
5
|
|
|
} |
6
|
|
|
|
7
|
|
|
function format_number(input) { |
8
|
|
|
if ($.fn.fmatter) { |
9
|
|
|
return $.fn.fmatter.number(input, $.jgrid.locales[$.jgrid.defaults.locale].formatter); |
10
|
|
|
} |
11
|
|
|
return input.toFixed(2); |
12
|
|
|
} |
13
|
|
|
|
14
|
|
|
function calculate_row(id) { |
15
|
|
|
var price_unit = parse_input($("#price_per_unit_" + id).val()), |
16
|
|
|
units = parse_input($("#units_" + id).val()), |
17
|
|
|
sum = 0; |
18
|
|
|
//check if they are numbers |
19
|
|
|
if (!isNaN(price_unit) && !isNaN(units)) { |
20
|
|
|
sum = price_unit * units; |
21
|
|
|
} |
22
|
|
|
$('#row_sum_' + id).html(format_number(sum)); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
function calculate_total(table) { |
26
|
|
|
var total = 0; |
27
|
|
|
table.find('tbody tr').each(function() { |
28
|
|
|
if ($(this).find('input[type="checkbox"]').is(':checked')) { |
29
|
|
|
total += parse_input($(this).find('.units').val()) * parse_input($(this).find('.price_per_unit').val()); |
30
|
|
|
} |
31
|
|
|
}); |
32
|
|
|
|
33
|
|
|
table.find('tfoot .totals').text(format_number(total)); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
function hide_invoice_address() { |
37
|
|
|
if ($('#org_openpsa_invoices_use_contact_address').is(':checked')) { |
38
|
|
|
$(".invoice_address").hide(); |
39
|
|
|
} else { |
40
|
|
|
$(".invoice_address").show(); |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
$(document).ready(function() { |
45
|
|
|
if ($('#org_openpsa_invoices_use_contact_address').length > 0) { |
46
|
|
|
hide_invoice_address(); |
47
|
|
|
$('#org_openpsa_invoices_use_contact_address').change(function() { |
48
|
|
|
hide_invoice_address(); |
49
|
|
|
}); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
$('.projects table') |
53
|
|
|
.on('change', 'input[type="text"]', function() { |
54
|
|
|
var task_id = $(this).closest('tr').attr('id').replace('task_', ''); |
55
|
|
|
calculate_row(task_id); |
56
|
|
|
calculate_total($(this).closest('table')); |
57
|
|
|
}) |
58
|
|
|
.on('change', 'input[type="checkbox"]', function() { |
59
|
|
|
calculate_total($(this).closest('table')); |
60
|
|
|
}) |
61
|
|
|
.each(function() { |
62
|
|
|
calculate_total($(this)); |
63
|
|
|
}) |
64
|
|
|
.parent().on('submit', function() { |
65
|
|
|
$(this).find('.numeric input').each(function() { |
66
|
|
|
$(this).val(parse_input($(this).val())); |
67
|
|
|
}); |
68
|
|
|
}); |
69
|
|
|
|
70
|
|
|
$('#add-journal-entry').on('click', function() { |
71
|
|
|
var button = $(this), |
72
|
|
|
dialog, |
73
|
|
|
options = { |
74
|
|
|
title: this.title, |
75
|
|
|
resizable: false, |
76
|
|
|
modal: true, |
77
|
|
|
buttons: {} |
78
|
|
|
}, |
79
|
|
|
form = $('<form action="' + MIDCOM_PAGE_PREFIX + '__mfa/org.openpsa.relatedto/rest/journalentry/" method="post">'), |
80
|
|
|
text = $('<input type="text" required name="title" class="add-journal-text">').appendTo(form), |
81
|
|
|
submit = $('<input type="submit">') |
82
|
|
|
.hide() |
83
|
|
|
.appendTo(form); |
84
|
|
|
|
85
|
|
|
options.buttons[this.dataset.dialogSubmitLabel] = function() { |
86
|
|
|
submit.click(); |
87
|
|
|
}; |
88
|
|
|
options.buttons[this.dataset.dialogCancelLabel] = function() { |
89
|
|
|
$( this ).dialog( "close" ); |
90
|
|
|
}; |
91
|
|
|
dialog = $('<div>') |
92
|
|
|
.append(form) |
93
|
|
|
.appendTo($('body')) |
94
|
|
|
.dialog(options); |
95
|
|
|
|
96
|
|
|
form.on('submit', function(e) { |
97
|
|
|
e.preventDefault(); |
98
|
|
|
$.post(this.action, { |
99
|
|
|
linkGuid: button.data('guid'), |
100
|
|
|
title: text.val() |
101
|
|
|
}, |
102
|
|
|
function () { |
103
|
|
|
dialog.dialog("close"); |
104
|
|
|
window.location.reload(); |
105
|
|
|
}); |
106
|
|
|
}); |
107
|
|
|
}); |
108
|
|
|
}); |
109
|
|
|
|